home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PROGRAMR
/
UPC12BS2.ZIP
/
RNEWS
/
EXPIRE.C
next >
Wrap
C/C++ Source or Header
|
1993-07-12
|
20KB
|
540 lines
/*--------------------------------------------------------------------*/
/* e x p i r e . c */
/* */
/* Expire old news articles for UUPC/extended */
/* */
/* Copyright (c) 1992-1993 by Kendra Electronic Wonderworks, all */
/* rights reserved except those explicitly granted by the UUPC/ */
/* extended license. */
/*--------------------------------------------------------------------*/
/*
* $Id: expire.c 1.5 1993/07/13 01:13:32 ahd Exp $
*
* $Log: expire.c $
* Revision 1.5 1993/07/13 01:13:32 ahd
* Drop unused stater.h header
*
* Revision 1.4 1993/04/05 04:32:19 ahd
* Add timestamp, size to information returned by directory searches
*
* Revision 1.3 1992/11/25 12:59:17 ahd
* Modifiy summery messages
*
*/
/*--------------------------------------------------------------------*/
/* System include files */
/*--------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <limits.h>
/*--------------------------------------------------------------------*/
/* UUPC/extended include files */
/*--------------------------------------------------------------------*/
#include "lib.h"
#include "active.h"
#include "dater.h"
#include "getopt.h"
#include "hlib.h"
#include "import.h"
#include "importng.h"
#include "logger.h"
#include "uundir.h"
#include "pushpop.h"
#include "timestmp.h"
currentfile();
/*--------------------------------------------------------------------*/
/* Global Variables */
/*--------------------------------------------------------------------*/
#define ONE_DAY (60L*60L*24L)
/*--------------------------------------------------------------------*/
/* Internal prototypes */
/*--------------------------------------------------------------------*/
static boolean numeric( char *start);
static void ExpireAll( const time_t expire_date,
const time_t archive_date );
static void ExpireGroup( const char *group,
const time_t expire_date,
const time_t archive_date );
static void ExpireOneGroup( struct grp *cur_grp,
const time_t expire_date,
const time_t archive_date );
static void ExpireDirectory( struct grp *cur_grp,
const time_t expire_date,
const char *directory,
const char *archive );
static boolean numeric( char *start);
static void usage( void );
long total_articles_purged = 0;
long total_articles_archived = 0;
long total_articles_kept = 0;
long total_bytes_purged = 0;
long total_bytes_archived = 0;
long total_bytes_kept = 0;
/*--------------------------------------------------------------------*/
/* m a i n */
/* */
/* Main program */
/*--------------------------------------------------------------------*/
void main( int argc, char **argv)
{
int c;
extern char *optarg;
extern int optind;
char *group = NULL;
time_t expire_period = 7; /* Seven days visible to users */
time_t archive_period = 0; /* Seven days after expiring in arch */
time_t expire_date;
time_t archive_date;
/*--------------------------------------------------------------------*/
/* Report our version number and date/time compiled */
/*--------------------------------------------------------------------*/
debuglevel = 1;
banner( argv );
#if defined(__CORE__)
copywrong = strdup(copyright);
checkref(copywrong);
#endif
/*--------------------------------------------------------------------*/
/* Process our arguments */
/*--------------------------------------------------------------------*/
while ((c = getopt(argc, argv, "e:a:g:x:n:")) != EOF)
switch(c) {
case 'a':
archive_period = atoi( optarg );
break;
case 'e':
expire_period = atoi( optarg );
break;
case 'n':
group = optarg;
break;
case 'x':
debuglevel = atoi( optarg );
break;
case '?':
usage();
exit(1);
break;
default:
printmsg(0, "expire - invalid option -%c", c);
usage();
exit(2);
break;
}
if (optind != argc) {
fputs("Extra parameter(s) at end.\n", stderr);
usage();
exit(2);
}
/*--------------------------------------------------------------------*/
/* Initialize */
/*--------------------------------------------------------------------*/
tzset(); /* Set up time zone information */
if (!configure( B_NEWS ))
exit(1); /* system configuration failed */
/*--------------------------------------------------------------------*/
/* Switch to the spooling directory */
/*--------------------------------------------------------------------*/
PushDir( E_newsdir );
atexit( PopDir );
/*--------------------------------------------------------------------*/
/* Initialize logging file */
/*--------------------------------------------------------------------*/
openlog( NULL );
/*--------------------------------------------------------------------*/
/* Load the active file */
/*--------------------------------------------------------------------*/
get_active(); /* Get sequence numbers for groups from
active file */
/*--------------------------------------------------------------------*/
/* Compute times for expiring files */
/*--------------------------------------------------------------------*/
time( &expire_date );
expire_date -= (expire_period * ONE_DAY);
archive_date = expire_date - (archive_period * ONE_DAY);
printmsg(1,"%s: %sing news older than %s (%ld days)",
argv[0],
archive_period ? "Archiv" : "Purg",
dater( expire_date , NULL), (long) expire_period );
if ( archive_period != 0 )
printmsg(1,"%s: Purging news older than %s",
argv[0],
dater( archive_date , NULL));
/*--------------------------------------------------------------------*/
/* Process one group if requested, otherwise process the entire */
/* active file */
/*--------------------------------------------------------------------*/
if ( group != NULL )
ExpireGroup( group, expire_date, archive_date );
else
ExpireAll(expire_date, archive_date );
/*--------------------------------------------------------------------*/
/* Clean up and exit */
/*--------------------------------------------------------------------*/
put_active();
if ( total_articles_purged || total_articles_archived)
printmsg(1,"%s: Purged %ld total articles (%ld bytes), "
"archived %ld total articles (%ld bytes). " ,
argv[0],
total_articles_purged, total_bytes_purged,